<%@ page import="cn.ecut.services.GoodServices" %>
<%@ page import="cn.ecut.model.User" %>
<%@ page import="cn.ecut.services.ApplyServices" %>
<%@ page import="cn.ecut.services.UserServices" %>
<%@ page import="cn.ecut.model.Good" %>
<%@ page import="java.util.List" %>
<%@ page import="cn.ecut.model.Apply" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page language="java" contentType="text/html; charset=utf-8" %>
<%
    if (session.getAttribute("user") == null) {
        response.sendRedirect("/login.jsp");
        return;
    }
    User user=(User)session.getAttribute("user");
//    User user = new User(1, "zhangsan", "qweasd", "123456", "男", "zhangsan@qq.com");
    GoodServices gservice=new GoodServices();
    ApplyServices aservice=new ApplyServices();
%>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <title>发布管理</title>
    <link href="${pageContext.request.contextPath}/css/bootstrap.min.css" type="text/css" rel="stylesheet">
    <script src="${pageContext.request.contextPath}/js/jquery-3.5.1.min.js"></script>
</head>

<body>
    <div class="container">
    <form method="post" action="">
        <div class="panel admin-panel">

            <div class="panel-head"><h2>申领请求管理</h2></div>
            <table class="table table-hover text-center">
                <tr>
                    <th width="8%">序号</th>
                    <th width="13%">申请物品</th>
                    <th width="8%">物品图片预览</th>
                    <th width="8%">申领人</th>
                    <th width="10%">联系方式</th>
                    <th width="10%">申请图片</th>
                    <th width="13%">申领理由</th>
                    <th width="8%">申领时间</th>
                    <th width="8%">状态</th>
                    <th width="15%">操作</th>
                </tr>
                <%
                    //user的发布的物品
                    List<Good> glist = gservice.loadByUserId(user.getUserid());
                	if(glist!=null||glist.size()>0){
                		int count=0;
                		for(int i=0;i<glist.size();i++){
                			Good g=glist.get(i);
                			//发布的物品的申领
                			List<Apply> alist=aservice.loadByGoodId(g.getGoodid());
                			if(alist!=null||alist.size()>0){
                				for(int j=0;j<alist.size();j++){
                					count++;
                					Apply a=alist.get(j);
                					//申领用户的信息（姓名）
                                    String applyuser=a.getUser().getUsername();
                					SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
               						String applytime = sdf1.format(a.getApplytime());
		            				
		            				String state="";
		            				if("0".equals(a.getApplystate())){
		            					state="<font color='#ff0000'>等待您处理</font>";
		            				}else if("1".equals(a.getApplystate())){
		            					state="已通过";
		            				}else if("2".equals(a.getApplystate())){
		            					state="已驳回";
		            				}
                %>
                <tr>
                    <td><%=count %></td>
                    <td><%=g.getGoodname()%></td>
                    <td height="100px"><img src="${pageContext.request.contextPath}<%=g.getGoodpicture() %>" alt="图片" width="100%" height="100%" /></td>
                    <td><%=applyuser %></td>
                    <td><%=a.getUser().getUserphone() %></td>
                    <td height="100px"><img src="${pageContext.request.contextPath}<%=a.getApplypicture() %>" alt="图片" width="100%" height="100%" /></td>
                    <td><%=a.getApplyexplain() %></td>
                    <td><%=applytime %></td>
                    <td><%=state %></td>
                    <td>
                        <div class="button-group">
                        <% if("0".equals(a.getApplystate())){
                        %>
                            <input type="button" name="" id="button1" onclick="pass(<%=a.getApplyid() %>)" value="通过">
                            <input type="button" name="" id="button2" onclick="del(<%=a.getApplyid() %>)" value="驳回">
                        <%
                        	}else{
                        %>
                            <input type="button" name="" id="button3" onclick="del2(<%=a.getApplyid() %>)" value="删除">
                        <%
                        	}
                        %>
                        </div>
                    </td>
                </tr>
                <%
                				}
                			}
                		}
                	}
                %>
            </table>
        </div>
    </form>
    </div>
    <script type="text/javascript">
        function pass(id) {
            if (confirm("您确定要通过吗?")) {
				window.location.href="${pageContext.request.contextPath}/apply/deal?passId="+id;
            }
        }

		function del(id) {
            if (confirm("您确定要驳回吗?")) {
				window.location.href="${pageContext.request.contextPath}/apply/deal?failId="+id;
            }
        }
        function del2(id) {
            if (confirm("您确定要删除吗?")) {
                window.location.href="${pageContext.request.contextPath}/apply/deal?deleteId="+id;
            }
        }
    </script>
</body>

</html>
